<script src="{{basePath}}/plugins/jquery.min.js"></script>
<script src="{{basePath}}/plugins/bootstrap.min.js"></script>
<script src="{{basePath}}/plugins/external.js"></script>
<script type="text/javascript">
window.layer = top.parent.layer;
window.enumObject = top.parent.enumObject;
</script>
<script src="{{basePath}}/plugins/common.js"></script>
<script src="{{basePath}}/js/utils/index.js"></script>
<script src="{{basePath}}/js/utils/buildSelect.js"></script>
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'token': common.getToken()
    },
    cache: false,
    dataType:'json',
    beforeSend: function(xhr, request) {
        if (!request.data) {
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            // request.contentType = "";
//            request.data = 'token=' + common.getToken();
            // 'token:' + common.getToken()
        } else {
//            request.data += '&token=' + common.getToken();
        }
//        request.data= request.data.replace(/[\r\n]/g,'');
        request.data= request.data;
    },
    dataFilter: function(data) {
        /**
         * 过滤返回数据中的换行和回车。
         */
        var __data = "{}";
        if (!!data) {
//            __data = data.replace(/[\r\n]/g, '');
            __data = data;
        }
        if (-1 !== this.dataTypes.join("").indexOf("json")) {
            var result = JSON.parse(__data);
            var msg = result["res"]["msg"];
            // 如果返回值状态码是101或者102，代表token为空（101）或token验证失败（102），那么就弹窗给予提示，并清空缓存，将页面跳转到登录页
            if (result["code"] == 101 || result["code"] == 102) {
                layer.alert(msg, function() {
                    localStorage.clear();
                    top.parent.location.href = './login.html';
                });
            }
        }
        return __data;
    }
});
</script>

</html>
